﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BarberShop.BLL;

public partial class MovieManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetMovieData();
        }
    }

    protected void btn_search_Click(object sender, EventArgs e)
    {
        GetMovieData();
    }

    //getData
    protected void GetMovieData()
    {
        string name = tx_movieName.Text.Trim();
        var data = MovieInfoBLL.GetMovieList(name);
        this.Grid_Movie.DataSource = data;
        this.Grid_Movie.DataBind();
    }

    protected void Grid_Movie_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            double size = Convert.ToDouble(e.Row.Cells[4].Text.ToString());
            string sizename = "";
            if (size / 1024 < 1024)
            {
                sizename = (size / (double)1024).ToString("N2") + "Kb";
            }
            else if (size / 1024 / 1024 < 1024)
            {
                sizename = (size / (double)1024 / (double)1024).ToString("N2") + "Mb";
            }
            else
            {
                sizename = (size / (double)1024 / (double)1024 / (double)1024).ToString("N2") + "Gb";
            }
            e.Row.Cells[4].Text = sizename;

            int timelength = Convert.ToInt32(e.Row.Cells[5].Text.ToString());
            e.Row.Cells[5].Text = new TimeSpan(0, 0, timelength).ToString();
        }
    }
    protected void Grid_Movie_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        this.Grid_Movie.PageIndex = e.NewSelectedIndex;
    }
}
